<template>
  <el-dialog
    draggable
    overflow
    :title="titleMap[mode]"
    v-model="visible"
    :width="700"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <sk-tabs type="border-card">
      <el-tab-pane ref="tab" label="信息">
        <el-form
          :model="form"
          :rules="rules"
          ref="dialogForm"
          label-width="100px"
          label-position="right"
        >
          <el-row>
            <el-col :span="22">
              <el-form-item label="交易单位" prop="name">
                <el-input v-model="form.name" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="22">
              <el-form-item label="简称" prop="sname">
                <el-input v-model="form.sname" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="联系人" prop="linkman">
                <el-input v-model="form.linkman" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="手机" prop="cellphone">
                <el-input v-model="form.cellphone" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="电话" prop="phone">
                <el-input v-model="form.phone" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="传真" prop="fax">
                <el-input v-model="form.fax" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="签约地点" prop="contracting_place">
                <el-input v-model="form.contracting_place" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="邮编" prop="postalcode">
                <el-input v-model="form.postalcode" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="法定代理人" prop="statutory_agent">
                <el-input v-model="form.statutory_agent" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="委托代理人" prop="entrusted_agent">
                <el-input v-model="form.entrusted_agent" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="22">
              <el-form-item label="开户行" prop="bank">
                <el-input v-model="form.bank" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="22">
              <el-form-item label="账户" prop="account">
                <el-input v-model="form.account" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="22">
              <el-form-item label="地址" prop="address">
                <el-input v-model="form.address" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="22">
              <el-form-item label="英文地址" prop="address_en">
                <el-input v-model="form.address_en" clearable></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="22">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" clearable></el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-tab-pane>
    </sk-tabs>
    <template #footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
    </template>
  </el-dialog>
</template>

<script>
// import skDicSelect from "@/components/skDicSelect";

export default {
  emits: ["success", "closed", "update:modeValue"],
  // components: { skDicSelect },
  data() {
    return {
      mode: "add",
      titleMap: {
        add: "新增交易单位",
        edit: "编辑交易单位",
      },
      form: {
        id: "",
        name: "",
        linkman: "",
        cellphone: "",
        phone: "",
        fax: "",
        address: "",
        spell: "",
        sort: 0,
        remark: "",
        enname: "",
        standard: 0,
        code: "",
        statutory_agent: "",
        entrusted_agent: "",
        bank: "",
        account: "",
        postalcode: "",
        contracting_place: "",
        address_en: "",
        sname: "",
      },
      rules: {
        name: [{ required: true, message: "请输入交易单位" }],
        sname: [{ required: true, message: "请输入简称" }],
      },

      visible: false,
      isSaveing: false,
    };
  },
  mounted() {},
  methods: {
    //显示
    close() {
      this.visible = false;
      this.$emit("update:modeValue", false);
      this.$emit("closed");
    },
    open(mode = "add") {
      this.mode = mode;
      this.visible = true;
      return this;
    },

    //表单提交方法
    submit() {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true;
          this.$API.basedata.trade.save
            .post(this.form)
            .then((res) => {
              if (res.code == 200) {
                this.$emit("success", this.form, this.mode);
                this.visible = false;
                this.$message.success("操作成功");
              }
            })
            .catch(() => {
              this.isSaveing = false;
            });
        }
      });
    },
    //表单注入数据
    setData(data) {
      Object.assign(this.form, data);
    },
  },
};
</script>

<style></style>
